
var ok1 =  new Promise((resolve, reject) => {
	resolve(' success')
})

var failed1 = new Promise((resolve, reject) => {
	// reject('failed')
})


var ok2 =   new Promise((resolve, reject) => {
	setTimeout(() => {
		resolve('f4 success')
	}, 2000)
})



var failed2 =  new Promise((resolve, reject) => {
	setTimeout(() => {
		console.log('failed2')
		
		// reject( )
	}, 1000)
})




async function hello () {
	console.log(' hello start')
	
	try{
		var a = await ok2;
		console.log('awaitResult = ', a)

	} catch(err) {
		console.warn(err, typeof err)
	}

	console.log('function end....')
}
/*
var ret = hello('刘阿勇')
console.log(ret)
ret.then(value => {
	console.log('value => ',value)
})
*/

if(!(typeof window === 'object' && window == this)) {
	console.log('-----------------------\n')
	const util = require('util')
	const fs = require('fs')

	function readFile (path) {
		return util.promisify(fs.readFile)(path)
	}


	readFile('./resouce/1.txt').then(data => {
		console.log(data + '')
	})

	async function getFilesData() {
		var data1 = await readFile('./resouce/1.txt')
		var data2 = await readFile('./resouce/2.txt')
		var data3 = await readFile('./resouce/3.txt')

		return data1 + data2 + data3
	}

	getFilesData().then(data => {
		console.log('getFilesData = ', data)
		
	})
}

